package cn.trda.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import cn.trda.constants.WebConstants;
import cn.trda.pojo.Logs;
import cn.trda.pojo.User;
import cn.trda.service.LogService;
import cn.trda.util.MySqlPageUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("logs/")
public class LogsController extends BaseController {
	@Autowired
	LogService logService;
	
	@RequestMapping(value="manage")
	public String logsManage(){
		return "logs";
	}
	/**
	 * 获取logs的分页【已测试】
	 * @param logs
	 * @param page
	 * @param rows
	 * @param session
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value="list")
	public Map<String,Object> logsList(Logs logs,Integer page,Integer rows,HttpSession session) throws Exception{
		User user=(User) session.getAttribute(WebConstants.SESSION_USER_KEY);
		logs.setUserid(user.getId());
		logs.setUsername(user.getUsername());
		Map<String,Object> map=new HashMap<String,Object>();
		List<Logs> list=logService.getList(logs, new MySqlPageUtil(page, rows));
		int count=logService.count(logs);
		map.put("rows", list);
		map.put("total", count);
		return map;
	}
	
	
}
